#include <stdio.h>
#include <float.h>
#include <stdlib.h>

typedef long double real;

#if ! defined(__cplusplus)
typedef unsigned char bool;
#define false 0
#define true  1
#endif

struct histogram_data {
    real partition;
    int ammount_of_elements;
};
struct histogram_data* histogram;
int partition_number = 10;

void histogram_init() {
    histogram = malloc(partition_number * sizeof(real));
    
    for (int i=0;i<partition_number;++i) {
        histogram[i].partition = (i*partition_number);
    }
}

void add_to_histogram(real number) {
    for (int j=0; j<partition_number;++j) {
            if((number >= histogram[j].partition && number < histogram[j+1].partition)||j==partition_number-1) {
            histogram[j].ammount_of_elements++;
            break;
        }
    }
}

/// @return 0 in case of success, something different in case of failure
int process_file(FILE* file, const char* name)
{
	real value = 0.0;
	int result = 0;
	while ( true )
	{
		while ( ( result = fscanf(file, "%Lf", &value) ) > 0 )
		{
            add_to_histogram(value);
		}
        
		if ( result == EOF )
			return 0;
	}
}

void print_histogram () {
    for (int j=0; j<partition_number; ++j) {
        printf("%4.1Lf | ", histogram[j].partition);
        for(int i=0; i<histogram[j].ammount_of_elements; ++i) {
            printf("%c", '*');
        }
        printf("\n");
    }
}

int process_file_name(const char* name)
{
	if ( name[0] == '-' )
		return 0;
    
	FILE* file = fopen(name, "r");
	if ( ! file )
	{
		fprintf(stderr, "Couldn't open %s\n", name);
		return 1;
	}
	int result = process_file(file, name);
	fclose(file);
	return result;
}

int main(int argc, char* argv[]) {
    histogram_init();
    
    if (argc == 1) {
        process_file(stdin, "stdin");

    }
    else {
        for ( int i = 1; i < argc; ++i ) {
            process_file_name(argv[i]);
        }
    }
    print_histogram();    
    free(histogram);
}